import request from './request.js'
const accountInfo = uni.getAccountInfoSync()
const appId = accountInfo.miniProgram.appId;
import config from '@/config.js'
import * as loginServer from '@/common/login.js';

function getVenue() {
	return request({
		url: `/systemj/venue/appId/${appId}`,
		method: 'get'
	})
}


function getOwnMemberInfo() {
	// return loginServer.getNowOpenId().then(()=>{
		const nowOpenId = uni.getStorageSync('nowOpenId');
		return request({
			url: `/systemj/member/getOwnMemberInfo?openId=${nowOpenId}`,
			method: 'get'
		})
	// })
}

function getSiteList(projectId) {
	return request({
		url: `/systemj/site/getSiteList/${projectId}`,
		method: 'get'
	})
}

function getDateOrderInfo(params) {
	return request({
		url: `/systemj/reserve/getDateOrderInfo`,
		method: 'get',
		params: params
	})
}

function maGetPrice(params) {
	const nowOpenId = uni.getStorageSync('nowOpenId');
	return request({
		url: `/systemj/reserve/maGetPrice?openId=${nowOpenId}`,
		method: 'get',
		params: params
	})
}

function userOrder(data) {
	uni.showLoading({
		title: '提交中...'
	})

	return request({
		url: '/systemj/reserve/maReserveVenueWithInfoList',
		method: 'post',
		params: data
	}).finally(() => {
		uni.hideLoading();
	});
}

/**
 * 确定返订单信息
 * @param {Object} data
 */
function maReserveVenueWithInfoList(data) {
	const nowOpenId = uni.getStorageSync('nowOpenId');
	return request({
		url: `/systemj/reserve/maReserveVenueWithInfoList?openId=${nowOpenId}`,
		method: 'post',
		params: data
	})
}

/**
 * 订单付款
 * @param {Object} id
 * @param {Object} data
 */
function payForOrder(id, data) {
	const nowOpenId = uni.getStorageSync('nowOpenId');
	return request({
		url: `/systemj/reserve/maPay/${id}?openId=${nowOpenId}`,
		method: 'post',
		params: data
	})
}

function rechargeCard(params) {
	const nowOpenId = uni.getStorageSync('nowOpenId');
	return request({
		url: `/systemj/member/maRecharge?openId=${nowOpenId}`,
		method: 'post',
		params: params
	})
}

/**
 * 获取余额
 */
function getMyBalance() {
	const nowOpenId = uni.getStorageSync('nowOpenId');
	return request({
		url: `/systemj/member/getMyBalance?openId=${nowOpenId}`,
		method: 'get'
	})
}
function listCanUse() {
	return request({
		url: `/systemj/projectConfig/listCanUse`,
		method: 'get'
	})
}
// 订单列表
function getMalist(params) {
	return request({
		url: `/systemj/siteOrder/malist`,
		method: 'get',
		params: params
	})
}

function getMaItemById(id) {
	return request({
		url: `/systemj/siteOrder/maGetInfo/${id}`,
		method: 'get'
	})
}

// 订单取消 id是orderId
function cancelOrder(id) {
	const nowOpenId = uni.getStorageSync('nowOpenId');
	return request({
		url: `/systemj/reserve/unSubscribeOrderMa/${id}?openId=${nowOpenId}`,
		method: 'post'
	})
}

function scanQrCode(id) {
	return request({
		url: `/systemj/siteOrder/scanQrCode/${id}`,
		method: 'post'
	})
}

function xfList(params) {
	return request({
		url: `/systemj/memberBalanceFlow/maListConsume`,
		method: 'get',
		params: params
	})
}
function czList(params) {
	return request({
		url: `/systemj/memberOrder/maList/recharge`,
		method: 'get',
		params: params
	})
}

function getMaInfo(params) {
	return request({
		url: `/systemj/statisitcs/getMaInfo`,
		method: 'get',
		params: params
	})
}
// 发送手机验证码
function getCaptchaSms(params) {
	return request({
		url: `/captchaSms`,
		method: 'get',
		params: params
	})
}
function maRebindMemberCard(phonenumber,code) {
	const nowOpenId = uni.getStorageSync('nowOpenId');
	return request({
		url: `/systemj/member/maRebindMemberCard/${phonenumber}/${code}?openId=${nowOpenId}`,
		method: 'get'
	})
}
// 订单取消 规则获取
function getCancelHint(orderId) {
	return request({
		url: `/systemj/reserve/getCancelHint/${orderId}`,
		method: 'get'
	})
}
//充值提示
function getMemberLevelTip(phonenumber,amount) { 
	return request({
		url: `/systemj/member/generateMyMemberLevelRemian/${phonenumber}/${amount}`,
		method: 'get'
	})
}
// 充值反馈
function maRechargeConfirm(params) {
	return request({
		url: `/systemj/member/maRechargeConfirm`,
		method: 'post',
		params: params
	})
}

function maPayConfirm(params) {
	return request({
		url: `/systemj/reserve/maPayConfirm`,
		method: 'post',
		params: params
	})
}
// 反馈页面提交
function miniappData(params) {
	return request({
		url: `/systemj/miniappData`,
		method: 'post',
		params: params
	})
}



export {
	getVenue,
	getOwnMemberInfo,
	getSiteList,
	getDateOrderInfo,
	maGetPrice,
	userOrder,
	maReserveVenueWithInfoList,
	payForOrder,
	getMyBalance,cancelOrder,getMalist,getMaItemById,xfList,czList,getMaInfo,
	listCanUse,rechargeCard,scanQrCode,
	getCaptchaSms,maRebindMemberCard,getCancelHint,
	maRechargeConfirm,maPayConfirm,
	getMemberLevelTip,miniappData
}
